import Mock from 'mockjs'

const staffs =  Mock.mock({
  'list|3-10': [{
    'id|+1': 1,
    'name|+1': ['梨花', '鲁花', '李华', '小敏', '哈哈'],
    'role|+1': [1, 2, 3],
    username: '@email',
    password: 'belulu@2020'
  }],
  'roles|4': [{
    'id|+1': 1,
    'name|+1': ['入库员', '出库员', '会计员', '审核员'],
    'alias|+1': ['editor', 'outer', 'cashier', 'auditor']
  }]
})

export default [
  {
    url: '/staff/getRoles',
    type: 'get',
    response: _ => {
      return {
        code: 200,
        data: staffs.roles
      }
    }
  },
  {
    url: '/staff/getStaffs',
    type: 'get',
    response: _ => {
      return {
        code: 200,
        data: staffs.list
      }
    }
  },
  {
    url: '/staff/updateStaff',
    type: 'post',
    response: config => {
      const { id, name, role, username, password } = config.body
      return {
        code: 200,
        data: { 
          id: id ? Number(id) : 99,
          role, name, username, password
        },
        msg: id ? '账号修改成功！' : '账号添加成功！'
      }
    }
  },
]
